<template>
  <view class="container">
    <view class="form">
      <view class="form-group">
        <text class="form-label">姓名：</text>
        <input class="form-input" type="text" v-model="name" />
      </view>
      <view class="form-group">
        <text class="form-label">出生日期：</text>
        <picker v-if="info" mode="date" :value="birth"  @change="bindDateChange">
        	<view class="uni-input">{{birth}}</view>
        </picker>
      </view>
      <view class="form-group">
        <text class="form-label">性别：</text>
        <radio-group v-model="gender" >
          <radio class="form-radio" value="F" :checked="gender=='M'">男</radio>
          <radio class="form-radio" value="M" :checked="gender=='F'">女</radio>
        </radio-group>
      </view>
      <view class="form-group">
        <text class="form-label">电话：</text>
        <input class="form-input" type="tel" v-model="phone" />
      </view>
      <view class="form-group">
        <text class="form-label">QQ：</text>
        <input class="form-input" type="text" v-model="qq" />
      </view>
	  <view class="form-group">
	    <text class="form-label">邮箱地址：</text>
	    <input class="form-input" type="text" v-model="mail" />
	  </view>
	  <view class="form-group">
	    <text class="form-label">学历</text>
	    <input class="form-input" type="text" v-model="education" />
	  </view>
	  <view class="form-group">
	    <text class="form-label">民族：</text>
	    <input class="form-input" type="text" v-model="nation" />
	  </view>
      <view class="form-group">
        <text class="form-label">家庭地址：</text>
        <input class="form-input" type="text" v-model="address" />
      </view>
      <view class="form-group">
        <button class="form-button" @click="submit">提交</button>
      </view>
    </view>
  </view>
</template>

<script>
	import dayjs from 'dayjs'
export default {
  data() {
    return {
      name: '',
      birth: '',
      gender: '',
      phone: '',
      qq: '',
      address: '',
	  mail:'',
	  education:'',
	  nation:'',
	  info:null
    }
  },
  mounted(){
	let that = this 
	uni.getStorage({
		key:'info',
		success:function(res){
			that.info = JSON.parse(res.data)
			that.name = that.info.name 
			that.phone = that.info.tel 
			that.qq = that.info.qq 
			that.mail = that.info.email 
			that.nation = that.info.nation 
			that.education = that.info.education
			let birth = that.info.birth
			birth =  dayjs(birth).format('YYYY-MM-DD')
			that.birth = birth
			that.gender = that.info.gender
			that.address = that.info.address 
		}
	})

  },
  methods: {
	  bindDateChange: function(e) {
	       this.birth = e.detail.value
	   },
    submit() {
		uni.request({
			url:'http://localhost:8085/api/employee/update',
			method:'POST',
			header : {'content-type':'application/x-www-form-urlencoded'},
			data:{
				user_id:this.info.user_id,
				user_name:this.name,
				birth:dayjs(this.birth),
				tel:this.phone,
				email:this.mail,
				gender:this.gender,
				address:this.address,
				nation:this.nation,
				education:this.education,
				qq:this.qq
			},
			success:function(res){
				let response = res.data 
				if(response.code ===200){
					uni.showToast({
						title:'修改成功',
						
					})
				}else{
					uni.showToast({
						title:'失败',
						icon:'error'
					})
				}
				
			}
		})
    },
  },
}
</script>

<style>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
}

.form {
  width: 80%;
}

.form-group {
  margin-bottom: 20px;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.form-label {
  font-size: 16px;
  width: 80px;
  text-align: right;
  margin-right: 20px;
}

.form-input {
  font-size: 16px;
  flex: 1;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 8px;
}

.form-radio {
  margin-right: 10px;
}

.form-button {
  background-color: #007aff;
  color: #fff;
  font-size: 10px;
  padding: 10px 20px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  
}
</style>
